package com.example.util;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.example.ruihuada.R;

import java.util.List;

public class BannerUtil {
    private static long lastClickTime = 0;
    private static long SPACE_TIME = 1000;

    /**
     * 加载只有一张图的Banner
     *
     * @param banner   banner
     * @param imgUrl   imgUrl
     * @param listener listener
     */
    public static void loadBanner(ConvenientBanner banner, List<String> imgUrl, OnItemClickListener listener) {
        banner.setPages(new BannerImgAdapter(), imgUrl).setOnItemClickListener(position -> {
            long currentTime = System.currentTimeMillis();
            if (currentTime - lastClickTime > SPACE_TIME) {
                lastClickTime = System.currentTimeMillis();
                listener.onItemClick(position);
            }
        })
                .setCanLoop(true)
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
                  .setPointViewVisible(false)
//                .setPageIndicator(new int[]{R.drawable.unselect_point, R.drawable.select_point})
                .startTurning(5000);
        if (imgUrl.size() <= 1) {
            banner.setCanLoop(false);
        }
    }
}
